/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cadi.levelsManager;

import com.cadi.aux.Coin;
import com.cadi.aux.CounterIntermediate;
import com.cadi.menu.MainMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

/**
 *
 * @author ApoZuniga
 */
public class LevelsCountIntermediate extends CounterIntermediate {
    private JLabel background;
    public LevelsCountIntermediate() {
        super();
        voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/cuentas2.wav"));
        voice.play();
        toMenu.setVisible(true);
        currentLevel = 1;
        
        listenerGood = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                totalActionPerformed(ae, 1);
                changeLevel();
            }
        };
        
        listenerBad = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                totalActionPerformed(ae, 0);
            }
        };
        
        objectOne = new Coin(2, "small");
        objectOne.setBounds(320, 200, 75, 75);
        container.add(objectOne, JLayeredPane.PALETTE_LAYER);
        objectTwo = new Coin(2, "small");
        objectTwo.setBounds(470, 200, 75, 75);
        container.add(objectTwo, JLayeredPane.PALETTE_LAYER);
        objectThree = new Coin(5, "small");
        objectThree.setBounds(620, 200, 75, 75);
        container.add(objectThree, JLayeredPane.PALETTE_LAYER);
        objectFour = new Coin(1, "small");
        objectFour.setBounds(770, 200, 75, 75);
        container.add(objectFour, JLayeredPane.PALETTE_LAYER);
        objectFive = new Coin(0, "small");
        objectFive.setBounds(920, 200, 75, 75);
        container.add(objectFive, JLayeredPane.PALETTE_LAYER);
        
        optionTotalOne = new JButton(new ImageIcon(getClass().getResource("/resources/9_50.png")));
        optionTotalOne.setBounds(300, 400, 180, 70);
        optionTotalOne.addActionListener(listenerBad);
        container.add(optionTotalOne, JLayeredPane.PALETTE_LAYER);
        optionTotalTwo = new JButton(new ImageIcon(getClass().getResource("/resources/10_50.png")));
        optionTotalTwo.setBounds(600, 400, 180, 70);
        optionTotalTwo.addActionListener(listenerGood);
        container.add(optionTotalTwo, JLayeredPane.PALETTE_LAYER);
        optionTotalThree = new JButton(new ImageIcon(getClass().getResource("/resources/11_50.png")));
        optionTotalThree.setBounds(900, 400, 180, 70);
        optionTotalThree.addActionListener(listenerBad);
        container.add(optionTotalThree, JLayeredPane.PALETTE_LAYER);
        background = new JLabel(new ImageIcon(getClass().getResource("/resources/fondo5.png")));
        background.setBounds(0, 0, 1280,800);
        container.add(background, JLayeredPane.PALETTE_LAYER);
        window.setVisible(true);
    }
    
    private void setLevelTwo() {
        objectOne.changeIcon(10);
        objectOne.setBounds(300, 200, 75, 75);
        objectTwo.changeIcon(2);
        objectTwo.setBounds(450, 200, 75, 75);
        objectThree.changeIcon(5);
        objectThree.setBounds(600, 200, 75, 75);
        objectFour.changeIcon(10);
        objectFour.setBounds(750, 200, 75, 75);
        objectFive.changeIcon(1);
        objectFive.setBounds(900, 200, 75, 75);
        optionTotalOne.setIcon(new ImageIcon(getClass().getResource("/resources/27.png")));
        optionTotalOne.setBounds(300, 400, 180, 70);
        optionTotalTwo.setIcon(new ImageIcon(getClass().getResource("/resources/29.png")));
        optionTotalTwo.setBounds(600, 400, 180, 70);
        optionTotalThree.setIcon(new ImageIcon(getClass().getResource("/resources/28.png")));
        optionTotalThree.setBounds(900, 400, 180, 70);
        
        optionTotalTwo.removeActionListener(listenerGood);
        optionTotalTwo.addActionListener(listenerBad);
        optionTotalThree.removeActionListener(listenerBad);
        optionTotalThree.addActionListener(listenerGood);
        window.repaint();
        voice.play();
    }
    
    private void setLevelThree() {
        objectOne.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectOne.setBounds(210, 200, 150, 100);
        objectTwo.changeIcon(10);
        objectTwo.setBounds(480, 200, 75, 75);
        objectThree.changeIcon(5);
        objectThree.setBounds(655, 200, 75, 75);
        objectFour.changeIcon(5);
        objectFour.setBounds(835, 200, 75, 75);
        objectFive.changeIcon(2);
        objectFive.setBounds(1015, 200, 75, 75);
        optionTotalOne.setIcon(new ImageIcon(getClass().getResource("/resources/37.png")));
        optionTotalOne.setBounds(300, 400, 180, 70);
        optionTotalTwo.setIcon(new ImageIcon(getClass().getResource("/resources/42.png")));
        optionTotalTwo.setBounds(600, 400, 180, 70);
        optionTotalThree.setIcon(new ImageIcon(getClass().getResource("/resources/40.png")));
        optionTotalThree.setBounds(900, 400, 180, 70);
        
        optionTotalTwo.removeActionListener(listenerBad);
        optionTotalTwo.addActionListener(listenerGood);
        optionTotalThree.removeActionListener(listenerGood);
        optionTotalThree.addActionListener(listenerBad);
        window.repaint();
        voice.play();
    }
    
    private void setLevelFour() {
        objectOne.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectOne.setBounds(150, 200, 150, 100);
        objectTwo.changeIcon(5);
        objectTwo.setBounds(430, 200, 75, 75);
        objectThree.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectThree.setBounds(610, 200, 150, 100);
        objectFour.changeIcon(2);
        objectFour.setBounds(890, 200, 75, 75);
        objectFive.changeIcon(2);
        objectFive.setBounds(1060, 200, 75, 75);
        optionTotalOne.setIcon(new ImageIcon(getClass().getResource("/resources/49.png")));
        optionTotalOne.setBounds(300, 400, 180, 70);
        optionTotalTwo.setIcon(new ImageIcon(getClass().getResource("/resources/47.png")));
        optionTotalTwo.setBounds(600, 400, 180, 70);
        optionTotalThree.setIcon(new ImageIcon(getClass().getResource("/resources/51.png")));
        optionTotalThree.setBounds(900, 400, 180, 70);
        
        optionTotalOne.removeActionListener(listenerBad);
        optionTotalOne.addActionListener(listenerGood);
        optionTotalTwo.removeActionListener(listenerGood);
        optionTotalTwo.addActionListener(listenerBad);
        window.repaint();
        voice.play();
    }
    
    private void setLevelFive() {
        objectOne.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectOne.setBounds(100, 200, 150, 100);
        objectTwo.changeIcon(10);
        objectTwo.setBounds(350, 200, 75, 75);
        objectThree.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectThree.setBounds(510, 200, 150, 100);
        objectFour.setIcon(new ImageIcon(getClass().getResource("/resources/billete20_big.jpeg")));
        objectFour.setBounds(770, 200, 150, 100);
        objectFive.changeIcon(10);
        objectFive.setBounds(1010, 200, 75, 75);
        optionTotalOne.setIcon(new ImageIcon(getClass().getResource("/resources/70.png")));
        optionTotalOne.setBounds(300, 400, 180, 70);
        optionTotalTwo.setIcon(new ImageIcon(getClass().getResource("/resources/90.png")));
        optionTotalTwo.setBounds(600, 400, 180, 70);
        optionTotalThree.setIcon(new ImageIcon(getClass().getResource("/resources/80.png")));
        optionTotalThree.setBounds(900, 400, 180, 70);
        
        optionTotalOne.removeActionListener(listenerGood);
        optionTotalOne.addActionListener(listenerBad);
        optionTotalThree.removeActionListener(listenerBad);
        optionTotalThree.addActionListener(listenerGood);
        window.repaint();
        voice.play();
    }
    
    private void changeLevel() {
        switch(currentLevel){
            case 1:
                setLevelTwo();
                currentLevel++;
                break;
            case 2:
                setLevelThree();
                currentLevel++;
                break;
            case 3:
                setLevelFour();
                currentLevel++;
                break;
            case 4:
                setLevelFive();
                currentLevel++;
                break;
            case 5:
                MainMenu main = new MainMenu();
                window.setVisible(false);
                break;
        }
    }
}
